<%@ include file="/init.jsp"%>


<%@page import="java.util.StringTokenizer"%>
<%@page import="com.liferay.portal.service.ListTypeServiceUtil"%>
<%@page import="com.liferay.portal.model.ListType"%>
<%@ include file="/init.jsp"%>
<portlet:resourceURL var="ajaxCallResourceURL" />

<%
ListType mappedFee = (ListType) request.getAttribute("mappedFee");
System.out.println("doing ID >>>" + mappedFee.getListTypeId());

List<ListType> mappedSubFees = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() );
System.out.println("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() +"<<<");

%>
		
		<aui:layout>
			<aui:column>
				<span class="hder" id="feesName_<%=mappedFee.getListTypeId() %>" ><%=mappedFee.getName() %></span>
			</aui:column>
		</aui:layout>
		
		<aui:layout>
	  	<aui:column columnWidth="33">
	  		<!--  this is the fees description -->
	  		<%
				//List<ListType> layoutName = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.layout");
				List<ListType> layoutName = ListTypeServiceUtil.getListTypes("processing.fees.cop");
				%>
	
				<strong>Zone/Layout</strong>
				<select disabled="disabled" name="layout_<%=mappedFee.getListTypeId() %>"  id="layout_<%=mappedFee.getListTypeId() %>" onchange="autoFill_<%=mappedFee.getListTypeId() %>()">
					<option style="font-style: italic; color: #A0A0A4" value="">--Please Select Layout--</option>
  	
			  	<%
			   
			  	for(int i=0; i<layoutName.size(); i++){
			  		ListType _layoutName = layoutName.get(i);
			  		//20|A02.COR.processingfees.IKOT OMIN
			  		StringTokenizer strTok = new StringTokenizer(_layoutName.getName(), "|");
			  		String fee = strTok.nextToken();
			  		String secondPart = strTok.nextToken();
			  		String ___layout = secondPart.substring(secondPart.indexOf("processingfees") + "processingfees.".length());
			  		System.out.println("fee>>" + fee);
			  		System.out.println("___layout>>" + ___layout);
			  		
			  	%>	
  				<option value="<%=fee %>"><%=___layout  %></option>
			  	<%
			  	}
			  	%>
				</select>
	  	</aui:column>
	  	<aui:column columnWidth="33">
	  		<!-- this is if there is drop down -->		
				<strong>Area (Sq Meters):</strong>
				<input readonly="readonly" onchange="autoFill_<%=mappedFee.getListTypeId() %>()" id="area_<%=mappedFee.getListTypeId() %>" name="area_<%=mappedFee.getListTypeId() %>" type="text"></input>
	  	</aui:column>
	  	<aui:column columnWidth="33">
	  		<!-- This for displaying of the result -->		
				<br><input class="resultbox" readonly="readonly" name="result_<%=mappedFee.getListTypeId() %>"  id="result_<%=mappedFee.getListTypeId() %>" type="text" value="">
	  	</aui:column>
	  </aui:layout>
	  
		<aui:layout>
			<aui:column>
			<button type="button" title="Compute" onClick="ComputeFee_<%=mappedFee.getListTypeId() %>();" 
			name="compute_result_<%=mappedFee.getListTypeId() %>" id="compute_result_<%=mappedFee.getListTypeId() %>" value="Compute">Compute</button>
				
			</aui:column>
		</aui:layout>
		
		


<script>
function autoFill_<%=mappedFee.getListTypeId() %>(){
	try{
			
			var i=0;
			var Present_layout = document.getElementById('layout_' + <%=mappedFee.getListTypeId() %>);
			var layout_Fixed = document.getElementById('layout_Fixed');
			
			for (i = 40200; i <= 100000; i++){
				var layout=document.getElementById('layout_' + i);
				
				if (layout !=null && layout !=""){
					for (j = 0; j <= layout.length-1; j++){
						if (layout.options[j].text==Present_layout.options[Present_layout.selectedIndex].text){						
							layout.selectedIndex=j;	
							layout_Fixed.selectedIndex=j;
						}					
					}		
					}
			  }
			
		}catch(err){
			alert(err.message);
		}
	}
function ComputeFee_<%=mappedFee.getListTypeId() %>(){
	
	try{
		var result = document.getElementById('result_<%=mappedFee.getListTypeId() %>');
		var area = document.getElementById('area_<%=mappedFee.getListTypeId() %>').value;
		var layout =  document.getElementById('layout_<%=mappedFee.getListTypeId() %>').value;
		result.value = parseFloat(layout * area).toFixed(2);
		hidePrintButton();
		computeTotal();
	}catch(err){
	  txt="There was an error on this page.\n\n";
	  err.message
	  txt+="Error description: " + err.description + "\n\n";
	  txt+="Click OK to continue.\n\n";
	  txt+=err.message + "\n\n";
	  alert(txt);
	}
	
}
</script>

